package initialize

import (
	"os"

	"main.go/global"
	"main.go/model/mall"
	"main.go/model/payment"
	"main.go/model/system"

	"go.uber.org/zap"
	"gorm.io/gorm"
)

func Gorm() *gorm.DB {
	return GormMysql()
}

func RegisterTables() {
	db := global.EVA_DB
	err := db.AutoMigrate(
		system.SysOperationRecord{},
		system.SysUser{},
		system.SysFileUploadFile{},

		mall.MallAddress{},
		mall.MallUser{},
		mall.MallOrder{},
		mall.MallGoodsCategory{},
		mall.MallGoodsInfo{},

		payment.PaymentConfig{},
		payment.PaymentStatistic{},
	)
	if err != nil {
		global.EVA_LOG.Error("register table failed", zap.Error(err))
		os.Exit(0)
	}
	global.EVA_LOG.Info("register table success")
}
